// Decompiled by GOOSIN CO,LTD Copyright 2010 Pavel Kouznetsov.
// home page: http://www.Goosin.net
// Decompiler options: packimports(3) fieldsfirst ansi space 
// Source File Name:   salaryStandard_draft_ok.java

package draft.hr;

import include.nseer_db.nseer_db_backup1;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.*;
import javax.servlet.jsp.JspFactory;
import validata.ValidataNumber;
import validata.ValidataTag;

public class salaryStandard_draft_ok extends HttpServlet
{

	ServletContext application;
	HttpSession session;

	public salaryStandard_draft_ok()
	{
	}

	public synchronized void service(HttpServletRequest request, HttpServletResponse response)
		throws IOException, ServletException
	{
		HttpSession dbSession = request.getSession();
		JspFactory _jspxFactory = JspFactory.getDefaultFactory();
		javax.servlet.jsp.PageContext pageContext = _jspxFactory.getPageContext(this, request, response, "", true, 8192, true);
		ServletContext dbApplication = dbSession.getServletContext();
		try
		{
			HttpSession session = request.getSession();
			PrintWriter out = response.getWriter();
			nseer_db_backup1 hr_db = new nseer_db_backup1(dbApplication);
			if (hr_db.conn((String)dbSession.getAttribute("unit_db_name")))
			{
				ValidataNumber validata = new ValidataNumber();
				ValidataTag vt = new ValidataTag();
				String standard_ID = request.getParameter("standard_ID");
				String standard_name = request.getParameter("standard_name");
				String major_type = request.getParameter("major_type");
				String designer = request.getParameter("designer");
				String item_name[] = request.getParameterValues("item_name");
				String salary[] = request.getParameterValues("salary");
				String details_number[] = request.getParameterValues("details_number");
				String register = request.getParameter("register");
				String register_time = request.getParameter("register_time");
				int p = 0;
				for (int i = 0; i < item_name.length; i++)
					if (!salary[i].equals(""))
					{
						StringTokenizer tokenTO4 = new StringTokenizer(salary[i], ",");
						String salary1;
						for (salary1 = ""; tokenTO4.hasMoreTokens(); salary1 = (new StringBuilder(String.valueOf(salary1))).append(tokenTO4.nextToken()).toString());
						if (!validata.validata(salary1))
							p++;
					}

				if (vt.validata((String)dbSession.getAttribute("unit_db_name"), "hr_salary_standard", "standard_ID", standard_ID, "check_tag").equals("5") || vt.validata((String)dbSession.getAttribute("unit_db_name"), "hr_salary_standard", "standard_ID", standard_ID, "check_tag").equals("9"))
				{
					if (p == 0)
					{
						int n = 0;
						double salary_sum = 0.0D;
						for (int i = 0; i < item_name.length; i++)
							if (!salary[i].equals(""))
							{
								StringTokenizer tokenTO4 = new StringTokenizer(salary[i], ",");
								String salary1 = "";
								while (tokenTO4.hasMoreTokens()) 
								{
									salary1 = (new StringBuilder(String.valueOf(salary1))).append(tokenTO4.nextToken()).toString();
									if (salary1.indexOf("-") != -1)
										n++;
								}
							}

						if (n == 0)
						{
							try
							{
								for (int i = 0; i < item_name.length; i++)
								{
									if (salary[i].equals(""))
										salary[i] = "0";
									String salarying = "";
									for (StringTokenizer tokenTO = new StringTokenizer(salary[i], ","); tokenTO.hasMoreTokens();)
										salarying = (new StringBuilder(String.valueOf(salarying))).append(tokenTO.nextToken()).toString();

									salary_sum += Double.parseDouble(salarying);
									String sql4 = (new StringBuilder("update hr_salary_standard_details set standard_name='")).append(standard_name).append("',salary='").append(salarying).append("' where standard_ID='").append(standard_ID).append("' and details_number='").append(details_number[i]).append("'").toString();
									hr_db.executeUpdate(sql4);
								}

								String sql2 = (new StringBuilder("update hr_salary_standard set standard_name='")).append(standard_name).append("',major_type='").append(major_type).append("',designer='").append(designer).append("',register='").append(register).append("',register_time='").append(register_time).append("',salary_sum='").append(salary_sum).append("' where standard_ID='").append(standard_ID).append("'").toString();
								hr_db.executeUpdate(sql2);
								String sql3 = (new StringBuilder("update hr_file set salary_standard_name='")).append(standard_name).append("',major_type='").append(major_type).append("',salary_sum='").append(salary_sum).append("' where salary_standard_ID='").append(standard_ID).append("'").toString();
								hr_db.executeUpdate(sql3);
							}
							catch (Exception ex)
							{
								out.println((new StringBuilder("error")).append(ex).toString());
							}
							response.sendRedirect("draft/hr/salaryStandard_ok.jsp?finished_tag=0");
						} else
						{
							response.sendRedirect("draft/hr/salaryStandard_ok.jsp?finished_tag=6");
						}
					} else
					{
						response.sendRedirect("draft/hr/salaryStandard_ok.jsp?finished_tag=7");
					}
				} else
				{
					response.sendRedirect("draft/hr/salaryStandard_ok.jsp?finished_tag=1");
				}
				hr_db.commit();
				hr_db.close();
			} else
			{
				response.sendRedirect("error_conn.htm");
			}
		}
		catch (Exception exception) { }
	}
}
